{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2 Solutions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 1\n",
    "### Part a\n",
    "We have to check the five properties listed in Definition 2.7. Firstly, let's look at closure. Our operation should take two elements of $\\mathbb{R}\\setminus\\{-1\\}$, and spit out a real number which isn't $-1$. Clearly we will get a real answer, so let's suppose we can get $-1$, and we'll hopefully find a contradiction. Let $a,b \\in \\mathbb{R}\\setminus\\{-1\\}$ be such that $-1 = ab + a+ b$. Then $ab+a+b+1 = 0$, so $(a+1)(b+1) = 0$. Therefore, either $a=-1$ or $b=-1$, which is a contradiction.\n",
    "\n",
    "Now, we attack associativity. We use the fact that $+$ is associative and commutative on $\\mathbb{R}$. We have\n",
    "\n",
    "$\\begin{align*}\n",
    "(a\\star b) \\star c & = (ab+a+b) \\star c \\\\\n",
    "& = (ab+a+b)c + (ab+a+b) + c \\\\\n",
    "& = abc + ac + bc + ab + a + b + c \\\\\n",
    "& = abc + ab + ac + a + bc + b + c \\\\\n",
    "& = a(bc+b+c) + a + (bc+b+c) \\\\\n",
    "& = a(b\\star c)+a + (b\\star c) \\\\\n",
    "& = a\\star (b\\star c).\n",
    "\\end{align*}$\n",
    "\n",
    "Observe that $a\\star 0 = a \\cdot 0 +a+0 = a$, and similarly $0\\star a = a$, so $0$ is the neutral element.\n",
    "\n",
    "Fourthly, we take $x \\star y = 0$ (the neutral element we found in the previous step). Solving for $y$ in terms of $x$, we find that $ y = \\frac{-x}{x+1}, $ which always exists, since $x\\neq -1$. Thus such a $y$ is the inverse element for $x \\in \\mathbb{R}\\setminus\\{-1\\}$. This concludes the argument that $(\\mathbb{R}\\setminus\\{-1\\},\\star)$ is a group.\n",
    "\n",
    "Finally, if we observe that $a\\star b = b \\star a$, by the commutativity of multiplication and addition of real numbers, then we can conclude that $(\\mathbb{R}\\setminus\\{-1\\},\\star)$ is an $abelian$ group.\n",
    "\n",
    "### Part b\n",
    "Let's compute the left hand side as $3\\star (x \\star x)$, say. We have $3 \\star (x^2+2x)$, and thus $3(x^2+2x)+(x^2+2x)+3 = 15$. From this, we obtain $4x^2+8x-12 = 0$, so $x=1$ or $x=-3$.  You can check that both of these do indeed work in the original equation.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 2\n",
    "### Part a\n",
    "The major thing we need to check here is whether the operation $\\oplus$ is well-defined. That is to say, if we take two different representatives of the same congruence classes, do we definitely get the same answer at the end? Let's take $a_1, a_2 \\in \\mathbb{Z} $ such that $\\overline{a_1} = \\overline{a_2}$, and similarly let $b_1, b_2 \\in \\mathbb{Z} $ such that $\\overline{b_1} = \\overline{b_2}$. We need to show that $\\overline{a_1}\\oplus \\overline{b_1} = \\overline{a_2} \\oplus \\overline{b_2}$. In other words, we need to show that $\\overline{a_1+b_1} = \\overline{a_2+b_2}$.\n",
    "\n",
    "By the definition of the congruence class, two classes $\\overline{a_1}$ and $\\overline{a_2}$ are equal in $\\mathbb{Z}_n$ if and only if $a_1 - a_2$ is a multiple of $n$. Let's say $a_1 - a_2 = k_1 n$ and ${b_1 - b_2 = k_2 n}$, for some $k_1, k_2 \\in \\mathbb{Z}$. Observe then that $(a_1+b_1)-(a_2+b_2) = (k_1+k_2)n$, and so $\\overline{a_1+b_1} = \\overline{a_2+b_2}$ indeed!\n",
    "\n",
    "From here, we use properties of addition in the integers to deduce that $(\\mathbb{Z}_n,\\oplus)$ is an abelian group.\n",
    "\n",
    "\n",
    "$\\overline{a}\\oplus\\overline{b} = \\overline{a+b}\\in \\mathbb{Z}_n$\n",
    "\n",
    "$(\\overline{a}\\oplus \\overline{b}) \\oplus \\overline{c} = \\overline{a+b} \\oplus \\overline{c} = \\overline{(a+b)+c} = \\overline{a+(b+c)} = \\overline{a} \\oplus \\overline{b+c} = \\overline{a}\\oplus (\\overline{b} \\oplus \\overline{c})$, where the middle equality follows from the associativity of $\\mathbb{Z}$.\n",
    "\n",
    "$\\overline{0}$ is the neutral element, since $\\overline{0} \\oplus \\overline{a} = \\overline{0+a} = \\overline{a}$, and similarly the other way round.\n",
    "\n",
    "Given $\\overline{a} \\in \\mathbb{Z}_n$, we have that $\\overline{-a} = \\overline {n-a}$ is the inverse element, since $\\overline{a} \\oplus \\overline{-a} = \\overline{a-a} = \\overline{0}$, indeed.\n",
    "\n",
    "Finally, $\\overline{a}\\oplus \\overline{b} = \\overline{a+b} = \\overline{b+a} = \\overline{b} \\oplus \\overline{a}$, so the group is abelian!\n",
    "\n",
    "### Part b\n",
    "\n",
    "Observe that the neutral element is $\\overline{1}$. For the inverses, we have $\\overline{1}^{-1} = \\overline{1}$, $\\overline{2}^{-1} = \\overline{3}$, $\\overline{3}^{-1} = \\overline{2}$, and  $\\overline{4}^{-1} = \\overline{4}$.\n",
    "All the axioms are satisfied, so $(\\mathbb{Z}_5\\setminus\\{\\overline{0}\\} , \\otimes)$ is a group.\n",
    "\n",
    "### Part c\n",
    "Observe that, for example, $\\overline{2}\\otimes \\overline{4} = \\overline{0}\\notin \\mathbb{Z}_8\\setminus\\{\\overline{0}\\}$, so the operation is not closed.\n",
    "\n",
    "### Part d\n",
    "If $n$ is prime, then every integer from $1$ to $n-1$ will be relatively prime to $n$. Let $a$ be such an integer. Then, by B\\'ezout's theorem, there exist integers $u, v$ such that $au+nv=1$. If we take this identity mod $n$, we have $\\overline{au} \\oplus \\overline{nv} = \\overline{1}$. But $nv$ is a multiple of $n$, so $\\overline{nv} = \\overline{0}$, and this simplifies to $\\overline{a} \\otimes \\overline{u} = \\overline{1}$ -- in other words, $\\overline{u}$ is the inverse of $\\overline{a}$. Also, if we take two integers $a$ and $b$, both of which are relatively prime to $n$, then the product $ab$ also cannot contain a factor of $n$, since $n$ is prime, so the operation is closed. The other properties follow immediately. This shows that we have a group. $\\lozenge$\n",
    "\n",
    "If $n$ is not prime, then we can say $n=ab$, where $a,b\\in \\mathbb{Z}$, with $1<a\\leq b<n$. But then $\\overline{a}\\otimes \\overline{b} = \\overline{ab} = \\overline{n} = \\overline{0}\\notin \\mathbb{Z}_n\\setminus\\{\\overline{0}\\}$, and so the operation is not closed.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 3\n",
    "Let\n",
    "$A_1 = \\begin{bmatrix}\n",
    "1 & x_1 & y_1 \\\\\n",
    "0 & 1 & z_1 \\\\\n",
    "0 & 0 & 1\n",
    "\\end{bmatrix}$\n",
    "and\n",
    "$A_2 = \\begin{bmatrix}\n",
    "1 & x_2 & y_2 \\\\\n",
    "0 & 1 & z_2 \\\\\n",
    "0 & 0 & 1\n",
    "\\end{bmatrix}\n",
    "\\in \\mathcal{G}$.\n",
    "\n",
    "Then $A_1A_2 =\n",
    "\\begin{bmatrix}\n",
    "1 & x_1+x_2 & y_1+x_1z_2+y_2 \\\\\n",
    "0 & 1 & z_1+z_2 \\\\\n",
    "0 & 0 & 1\n",
    "\\end{bmatrix}\n",
    "\\in\\mathcal{G}$, so we have closure.\n",
    "\n",
    "Associativity follows from the associativity of standard matrix multiplication.\n",
    "\n",
    "Letting $x=y=z=0$, observe that the identity is in $\\mathcal{G}$.\n",
    "\n",
    "Finally, if we take $x_2 = -x_1$, $z_2 = -z_1$, and $y_2 = -y_1-x_1z_2$, then observe that $A_1A_2 = I_3$, and thus inverses are of the required form! Therefore, $\\mathcal{G} $ is a group.\n",
    "\n",
    "The group is not abelian, e.g. take $x_1=z_2=1$ and everything else to be $0$. Then multiplying these matrices in the other order (i.e. $x_2=z_1=1$) gives a different answer.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 4\n",
    "### Part a\n",
    "The numbers of columns in the first matrix must equal the number of rows in the second, so this product is not defined.\n",
    "### Part b\n",
    "$\\begin{bmatrix}\n",
    "4&3&5\\\\\n",
    "10&9&11\\\\\n",
    "16&15&17\n",
    "\\end{bmatrix}$\n",
    "### Part c\n",
    "$\\begin{bmatrix}\n",
    "5&7&9\\\\\n",
    "11&13&15\\\\\n",
    "8&10&12\n",
    "\\end{bmatrix}$\n",
    "### Part d\n",
    "$\\begin{bmatrix}\n",
    "14&6\\\\-21&2\n",
    "\\end{bmatrix}$\n",
    "### Part e\n",
    "$\\begin{bmatrix}\n",
    "12&3&-3&-12\\\\-3&1&2&6\\\\\n",
    "6&5&1&0\\\\\n",
    "13&12&3&2\n",
    "\\end{bmatrix}$\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 5\n",
    "### Part a\n",
    "Let's do some Gaussian elimination. We start with\n",
    "$\\left[\n",
    "\\begin{array}{cccc|c}\n",
    "1&1&-1&-1&1\\\\\n",
    "2&5&-7&5&-2\\\\\n",
    "2&-1&1&3&4\\\\\n",
    "5&2&-4&2&6\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Taking $r_2-2r_1$, $r_3-2r_1$ and $r_4-5r_1$, we have\n",
    "$\\left[\n",
    "\\begin{array}{cccc|c}\n",
    "1&1&-1&-1&1\\\\\n",
    "0&3&-5&7&-4\\\\\n",
    "0&-3&3&5&2\\\\\n",
    "0&-3&1&7&1\n",
    "\\end{array}\\right]\n",
    "$.\n",
    "\n",
    "Now taking $r_3+r_2$ and $r_4+r_2$, we have\n",
    "$\\left[\n",
    "\\begin{array}{cccc|c}\n",
    "1&1&-1&-1&1\\\\\n",
    "0&3&-5&7&-4\\\\\n",
    "0&0&-2&12&-2\\\\\n",
    "0&0&-4&-14&-3\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Finally, taking $r_4-2r_3$, we have\n",
    "$\\left[\n",
    "\\begin{array}{cccc|c}\n",
    "1&1&-1&-1&1\\\\\n",
    "0&3&-5&7&-4\\\\\n",
    "0&0&-2&12&-2\\\\\n",
    "0&0&0&-10&1\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Observe that the rank of the augmented matrix (4) is equal to rank of matrix of coefficients, so there exist a  solution set.\n",
    "\n",
    "$10x_4 = 1 \\Rightarrow x_4 = 0.1$\n",
    "\n",
    "$-2x_3 + 12x_4 = -2 \\Rightarrow -2x_3 + 1.2 = -2 \\Rightarrow x_3 = 1.6$\n",
    "\n",
    "$3x_2 + -5x_3 + 7x_4 = -4 \\Rightarrow 3x_2 -8 + 0.7 = -4 \\Rightarrow x_2 = 1.1$\n",
    "\n",
    "$1x_1 + 1x_2 + -1x_3 + -1x_4 = 1 \\Rightarrow 1x_1 + 1.1 - 1.6 - 0.1 = 1  \\Rightarrow x_1 = 1.6$\n",
    "\n",
    "### Part b\n",
    "We proceed with some more Gaussian elimination. From the start, we do $r_2-r_1$, $r_3-2r_1$, and $r_4+r_1$, to obtain\n",
    "$\\left[\n",
    "\\begin{array}{ccccc|c}\n",
    "1&-1&0&0&1&3\\\\\n",
    "0&2&0&-3&-1&3\\\\\n",
    "0&1&0&1&-3&-1\\\\\n",
    "0&1&0&-2&0&2\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "From here, do $r_2-2r_3$ and $r_4-r_3$ to obtain\n",
    "$\\left[\n",
    "\\begin{array}{ccccc|c}\n",
    "1&-1&0&0&1&3\\\\\n",
    "0&0&0&-5&5&5\\\\\n",
    "0&1&0&1&-3&-1\\\\\n",
    "0&0&0&-3&3&3\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Next, if we divide $r_2$ by $-5$, and then do $r_4+3r_2$, we have\n",
    "$\\left[\n",
    "\\begin{array}{ccccc|c}\n",
    "1&-1&0&0&1&3\\\\\n",
    "0&0&0&1&-1&-1\\\\\n",
    "0&1&0&1&-3&-1\\\\\n",
    "0&0&0&0&0&0\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Now, we do $r_1+r_3$, then swap $r_2$ and $r_3$, to give\n",
    "$\\left[\n",
    "\\begin{array}{ccccc|c}\n",
    "1&0&0&1&-2&2\\\\\n",
    "0&1&0&1&-3&-1\\\\\n",
    "0&0&0&1&-1&-1\\\\\n",
    "0&0&0&0&0&0\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Finally, let's do $r_1-r_3$ and $r_2-r_3$, to obtain\n",
    "$\\left[\n",
    "\\begin{array}{ccccc|c}\n",
    "1&0&0&0&-1&3\\\\\n",
    "0&1&0&0&-2&0\\\\\n",
    "0&0&0&1&-1&-1\\\\\n",
    "0&0&0&0&0&0\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Let's turn these back into equations. We have $x_1-x_5=3$, $x_2-2x_5=0$ and $x_4-x_5=-1$. Thus we can take $x_3$ and $x_5$ to be arbitrary, and then the others are determined. This gives a solution set of $\\{ (\\alpha+3, 2\\alpha, \\beta, \\alpha-1, \\alpha)^{\\mathsf{T}} : \\alpha, \\beta \\in \\mathbb{R} \\}$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 6\n",
    "We start with doing $r_3-r_1$, to give us\n",
    "$\\left[\n",
    "\\begin{array}{cccccc|c}\n",
    "0&1&0&0&1&0&2\\\\\n",
    "0&0&0&1&1&0&-1\\\\\n",
    "0&0&0&0&-1&1&-1\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Next, do $r_1+r_3$, $r+2+r_3$, and then multiply $r_3$ by $-1$. This gives\n",
    "$\\left[\n",
    "\\begin{array}{cccccc|c}\n",
    "0&1&0&0&0&1&1\\\\\n",
    "0&0&0&1&0&1&-2\\\\\n",
    "0&0&0&0&1&-1&1\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "This corresponds to the equations $x_2+x_6=1$, $x_4+x_6=-2$, and $x_5-x_6 = 1$. Now we can take $x_1$, $x_3$ and $x_6$ to be arbitrary, giving a solution set of $\\{ (\\alpha, 1-\\beta, \\gamma, -2-\\beta, 1+\\beta, \\beta)^{\\mathsf{T}} : \\alpha,\\beta, \\gamma \\in \\mathbb{R} \\}$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 7\n",
    "Here, we are looking for eigenvectors associated with the eigenvalue $12$. Indeed, we don't yet know that $12$ is an eigenvalue, but if we find ourselves unable to find such an eigenvector, then we can answer that the solution set will be empty.\n",
    "\n",
    "We have that $A-12I = \\begin{bmatrix}-6&4&3\\\\\n",
    "6&-12&9\\\\\n",
    "0&8&-12\n",
    "\\end{bmatrix}$, and observe that $(3,3,2)^{\\mathsf{T}} \\in \\ker(A-12I)$, so this is an eigenvector (and $12$ is an eigenvalue indeed!). Finally, we want an eigenvector such that the sum of the components is $1$, so simply divide the eigenvector above by $3+3+2=8$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 8\n",
    "### Part a\n",
    "Observe that $\\det A = 2(24-25) -3(18-20) + 4(15-16) = -2+6-4=0$, so $A$ is not invertible.\n",
    "\n",
    "### Part b\n",
    "We perform Gaussian elimination on\n",
    "$\\left[\n",
    "\\begin{array}{cccc|cccc}\n",
    "1&&1&&1&&&\\\\\n",
    "&1&1&&&1&&\\\\\n",
    "1&1&&1&&&1&\\\\\n",
    "1&1&1&&&&&1\n",
    "\\end{array}\n",
    "\\right]$, where a blank space denotes a 0.\n",
    "\n",
    "Firstly, with $r_3-r_1$, $r_4-r_1$, $r_3-r_2$, and $r_4-r_2$, we have\n",
    "$\\left[\n",
    "\\begin{array}{cccc|cccc}\n",
    "1&&1&&1&&&\\\\\n",
    "&1&1&&&1&&\\\\\n",
    "&&-2&1&-1&-1&1&\\\\\n",
    "&&-1&&-1&-1&&1\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Then with $r_1+r_4$, $r_2+r_4$, and $r_3-2r_4$, we have\n",
    "$\\left[\n",
    "\\begin{array}{cccc|cccc}\n",
    "1&&&&&-1&&1\\\\\n",
    "&1&&&-1&&&1\\\\\n",
    "&&&1&1&1&1&-2\\\\\n",
    "&&-1&&-1&-1&&1\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "Finally, swapping $r_3$ and $r_4$, then multiplying $r_3$ by $-1$, we have\n",
    "$\\left[\n",
    "\\begin{array}{cccc|cccc}\n",
    "1&&&&&-1&&1\\\\\n",
    "&1&&&-1&&&1\\\\\n",
    "&&1&&1&1&&-1\\\\\n",
    "&&&1&1&1&1&-2\n",
    "\\end{array}\n",
    "\\right]$.\n",
    "\n",
    "The matrix to the right of the vertical line is the inverse of $A$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 9\n",
    "### Part a\n",
    "We can relabel $\\mu^3$ as $\\nu$, so $\\nu$ can be any real number, and then we have $A = \\{ (\\lambda, \\lambda+\\nu, \\lambda-\\nu)^{\\mathsf{T}} : \\lambda, \\nu \\in \\mathbb{R} \\}$. This has a basis of $\\{(1,1,1)^{\\mathsf{T}}, (0,1,-1)^{\\mathsf{T}}\\}$, so it is a subspace of $\\mathbb{R}^3$.\n",
    "\n",
    "### Part b\n",
    "We cannot do the same trick as before, since the square of a real number is always at least zero. Clearly $(1,-1,0)^{\\mathsf{T}}\\in B$, but $-1$ times this vector, i.e.~$(-1,1,0)^{\\mathsf{T}}\\notin B$, and thus $B$ is not a subspace.\n",
    "\n",
    "### Part c\n",
    "We know that $(0,0,0)^{\\mathsf{T}}$ is an element of every (three-dimensional!) subspace, so we can $C$ can only be a subspace if $\\gamma = 0$. In this case, we can find a basis for $C$ (say $\\{ (3,0,-1)^{\\mathsf{T}},(0,3,2)^{\\mathsf{T}} \\}$), and conclude that it is indeed a subspace.\n",
    "\n",
    "### Part d\n",
    "Again, this is not a subspace. Observe that $(0,1,0)^{\\mathsf{T}}\\in D$, so if $D$ were a subspace, then any (real!) multiple should be in $D$ also. However, $\\frac12 (0,1,0)^{\\mathsf{T}} \\notin D$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 10\n",
    "### Part a\n",
    "If we form a matrix out of these three vectors and compute its determinant, we get zero. Thus, the vectors are not linearly independent.\n",
    "\n",
    "### Part b\n",
    "Let's form the equation $\\alpha_1 x_1 + \\alpha_2 x_2 + \\alpha_3 x_3 = 0$. These three vectors are linearly independent if and only if the $only$ solution to this equation is $\\alpha_1=\\alpha_2=\\alpha_3=0$.\n",
    "\n",
    "Looking at the third component, we have that $\\alpha_1\\cdot 1 + \\alpha_2 \\cdot 0 + \\alpha_3 \\cdot 0 = 0$, that is to say, $\\alpha_1 = 0$.\n",
    "\n",
    "Next, look at the second component. We already know $\\alpha_1 = 0$, so we have $\\alpha_2 \\cdot 1 + \\alpha_3 \\cdot 0 = 0$, that is to say $\\alpha_2=0$ also.\n",
    "\n",
    "Finally, look at the first component. We have that $\\alpha_3 \\cdot 1 = 0$, so all of the $\\alpha_i$'s are zero. Therefore, our three vectors are linearly independent.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 11\n",
    "Here, we need to solve the simultaneous equations $\\alpha_1+\\alpha_2+2\\alpha_3 = 1$, $\\alpha_1+2\\alpha_2-\\alpha_3=-2$, and $\\alpha_1+3\\alpha_2+\\alpha_3 = 5$.\n",
    "\n",
    "Performing Gaussian elimination in the usual way, we determine that $\\alpha_1 = -6$, $\\alpha_2 = 3$, and $\\alpha_3 = 2$. That is to say, $y=-6x_1+3x_2+2x_3$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 12\n",
    "We write the given vectors as $v_1, \\dots v_6$ from left to right. Firstly, observe that $\\dim(U_1)=2$ and $\\dim(U_2)=2$ (compute the rank of $\\left[v_1|v_2|v_3\\right]$, then $\\left[v_4|v_5|v_6\\right]$). Since we can write $v_3= \\frac13 (v_1-2v_2)$ and $v_6=-v_4-2v_5$, we need not consider $v_3$ and $v_6$ any further.\n",
    "\n",
    "Now, if we find the rank of $\\left[v_1|v_2|v_4|v_5\\right]$, we get 3, so $\\dim(U_1+U_2)=3$. Therefore, $\\dim(U_1\\cap U_2) = 2+2-3=1$. Hence, to find a basis of $U_1 \\cap U_2$, we need only find any non-zero vector in the space.\n",
    "\n",
    "Let $0\\neq v \\in U_1\\cap U_2$. Then we can write $v=\\alpha_1v_1 + \\alpha_2v_2$, and $v=\\alpha_4v_4 + \\alpha_5v_5$. Subtracting these equations, we have $0=\\alpha_1v_1 + \\alpha_2v_2 -\\alpha_4v_4 - \\alpha_5v_5$. Remember we want a non-zero solution for $v$, and observe that the rank of $\\left[v_1|v_2|v_4\\right]$ is 3 (i.e.~these three vectors are linearly independent). Hence we can take $\\alpha_5=9$, say (this means we don't have fractions later, but there's no way to know this a priori!), and solve for the other $\\alpha_i$'s. Using Gaussian elimination, we obtain $\\alpha_1=4$, $\\alpha_2=10$ and $\\alpha_4 = -6$. Thus \n",
    "$\\begin{equation*}\n",
    "v=4v_1+10v_2 = -6v_4+9v_5 = \\begin{bmatrix}\n",
    "24\\\\-6\\\\-12\\\\-6\n",
    "\\end{bmatrix}.\n",
    "\\end{equation*}$\n",
    "\n",
    "Finally, we can write our basis of $U_1\\cap U_2$ as just $\\{ v \\}$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 13\n",
    "### Part a\n",
    "We can compute $rank({A_1})=2$ and $rank({A_2})=2$ also. Since both matrices map from $\\mathbb{R}^3$ to $\\mathbb{R}^4$, we must have that the nullity of both of the matrices is 1. Therefore, $U_1$ and $U_2$ both have dimension 1, since they $are$ the kernels of their respective maps.\n",
    "\n",
    "### Part b\n",
    "Since the spaces have dimension 1, we are again simply looking for a non-zero vector in each space. Observe that $(1,1,-1)^{\\mathsf{T}}$ lies in both spaces, so $\\{ (1,1,-1)^{\\mathsf{T}} \\}$ is a basis for both.\n",
    "\n",
    "### Part c\n",
    "From the previous part, we have that $U_1=U_2$, so $U_1\\cap U_2 = U_1$ also, and again has $\\{ (1,1,-1)^{\\mathsf{T}} \\}$ as a basis.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 14\n",
    "### Part a\n",
    "Observe that these matrices are the same as those used in the previous parts, except now our spaces $U_1$ and $U_2$ are different. We now have $\\dim (U_1)=rank(A_1)=2$ and $\\dim(U_2) = rank (A_2)=2$.\n",
    "\n",
    "### Part b\n",
    "We are looking for two linearly independent columns in each of our matrices -- we need two non-zero columns, and they can't be a multiple of each other. For example, the first two columns of each matrix will do as a basis for each space.\n",
    "\n",
    "### Part c\n",
    "Note that $rank([A_1|A_2])=3$, i.e.~$\\dim(U_1+U_2)=3$ (Note that $[A_1|A_2]$ is just the $4\\times 6$ matrix formed by concatenating $A_1$ and $A_2$.) This means that $\\dim (U_1\\cap U_2) = \\dim(U_1)+\\dim(U_2)-\\dim(U_1+U_2) = 2+2-3=1$, so again, to find a basis of $U_1\\cap U_2$, we need only find a non-zero vector in the space. We proceed in a similar way to Question 2.12.\n",
    "\n",
    "Firstly, we observe that we can write $v_3=v_1+v_2$ and $v_6=v_4+v_5$, so these two vectors can safely be ignored. Secondly, observe that $\\left[v_1|v_2|v_5\\right]$ has rank three, so (using the notation of Question 12) if we take $\\alpha_4=1$, say, and solve then we have $\\alpha_1=3$, $\\alpha_2=1$, and $\\alpha_5=0$. In other words, our non-zero vector is $3v_1+v_2 = v_4 = (3,1,7,3)^{\\mathsf{T}}$, and our basis of $U_1\\cap U_2$ is $\\{ (3,1,7,3)^{\\mathsf{T}} \\}$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 15\n",
    "### Part a\n",
    "Firstly, observe that $(0,0,0) \\in F$, and $(0,0,0)\\in G$ also. Next, we check that adding any two elements of the set does indeed get us another element of the set. Finally, if we multiply any element of the set by any real number, we again get another element of the required form. Thus $F$ and $G$ are subspaces indeed!\n",
    "\n",
    "### Part b\n",
    "A vector in $F\\cap G$ will satisfy both conditions in the sets, so if we put $G$'s condition into $F$'s, we find $(a-b)+(a+b)-(a-3b) = 0$, from which we have $a=-3b$. Thus, $F\\cap G = \\{ (-4b,-2b,-6b) : b\\in \\mathbb{R} \\} = span[ (2,1,3)]$.\n",
    "\n",
    "### Part c\n",
    "Doing the same dimensional analysis as the previous three questions, we find that $F\\cap G$ has dimension 1. We have $F=span[(1,0,1), (0,1,1)]$, and $G=span[ (1,1,1),(-1,1,-3)]$.\n",
    "\n",
    "Proceeding in the same way as before, we find that $-4v_1-2v_2 = -3v_3+v_4$, and hence $\\{(-4,-2,-6)\\}$ is a basis of $F \\cap G$, which agrees with Part b.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 16\n",
    "### Part a\n",
    "Observe that $\\Phi(f+g) = \\int_a^b (f+g)(x) dx = \\int_a^b f(x) + g(x) dx = \\int_a^bf(x) dx +\\int_a^b g(x) dx = \\Phi(f) + \\Phi(g)$, and similarly $\\Phi(\\alpha f) = \\alpha \\Phi(f)$, for all real $\\alpha$, so $\\Phi$ (that is to say, definite integration) is indeed linear!\n",
    "\n",
    "### Part b\n",
    "Similarly to the previous part, we know that differentiation is indeed linear.\n",
    "\n",
    "### Part c\n",
    "This is not linear -- $\\Phi$ doesn't even map 0 to 0, indeed!\n",
    "\n",
    "### Part d\n",
    "We know from 2.7.1 that any matrix transformation like this is indeed linear. This comes from distributive properties of matrix multiplication.\n",
    "\n",
    "### Part e\n",
    "As before, this mapping is also linear. Indeed, this represents a clockwise rotation by $\\theta$ about the origin. (See 3.9.1)\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 17\n",
    "From the coefficients on the right, we have $A_\\Phi =\n",
    "\\begin{bmatrix}\n",
    "3&2&1\\\\\n",
    "1&1&1\\\\\n",
    "1&-3&0\\\\\n",
    "2&3&1\n",
    "\\end{bmatrix}$.\n",
    "\n",
    "Using Gaussian elimination, we can compute that $rank(A_\\Phi) = 3$. From this we deduce that the kernel is trivial (i.e.~only $(0,0,0)$), and clearly $Im(\\Phi)= \\{ (3x_1+2x_2+x_1,x_1+x_2+x_3,x_1-3x_2,2x_1+3x_2+x_3)^{\\mathsf{T}} : x_1, x_2, x_3 \\in \\mathbb{R} \\}$. We have $\\dim(\\ker(\\Phi))=0$, and $\\dim(Im(\\Phi))=rank(A_\\Phi)=3$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 18\n",
    "We have two automorphisms, which means they map linearly and bijectively from the space, $E$, to itself. The maps therefore both have kernel $\\{0\\}$ (by injectivity) and image $E$ (by surjectivity). From this, we immediately deduce that $\\ker(f)\\cap Im(g) = \\{0\\}$, indeed. Similarly, we deduce that $g\\circ f$ also has kernel $\\{0\\}$ and image $E$, as required. Note that we didn't need the condition that $f\\circ g = id_E$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 19\n",
    "### Part a\n",
    "Note that $rank(A_\\Phi) = 3$, so $\\ker(\\Phi)=\\{0\\}$ and $Im(\\Phi)=\\mathbb{R}^3$.\n",
    "\n",
    "### Part b\n",
    "Let $P$ be the change of basis matrix from the standard basis of $B$ to $\\mathbb{R}^3$. Then $P=\\begin{bmatrix}\n",
    "1&1&1\\\\\n",
    "1&2&0\\\\\n",
    "1&1&0\n",
    "\\end{bmatrix}$.\n",
    "\n",
    "The matrix $\\overline{A_\\Phi}$ is given by $P^{-1}A_\\Phi P = \\begin{bmatrix}\n",
    "6&9&1\\\\-3&-5&0\\\\-1&-1&0\n",
    "\\end{bmatrix}$.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 20\n",
    "### Part a\n",
    "Each set $B$ and $B'$ has the correct number of (clearly!)~linearly independent vectors, so they are both bases of $\\mathbb{R}^2$.\n",
    "\n",
    "### Part b\n",
    "We write the old basis vectors ($B'$) in terms of the new ($B$), and then transpose the matrix of coefficients. We have $b_1' = 4 b_1 + 6 b_2$, and $b_2' = 0b_1 -b_2$. Thus $P_1 = \\begin{bmatrix}\n",
    "4 & 0\\\\\n",
    "6 & -1\n",
    "\\end{bmatrix}$.\n",
    "\n",
    "### Part c\n",
    "Let $M=[c_1|c_2|c_3]$, and observe that $\\det M = 4 \\neq 0$, so the vectors are linearly independent. Since $\\mathbb{R}^3$ had dimension 3, and we have three linearly independent vectors, $C$ must indeed be a basis.\n",
    "\n",
    "\n",
    "Indeed, such an $M$ is the change of basis matrix from $C$ to $C'$ (write the old vectors in terms of the new!) and this is thus the $P_2$ we require. Thus $P_2 = \\begin{bmatrix}\n",
    "1&0&1\\\\\n",
    "2&-1&0\\\\-1&2&-1\n",
    "\\end{bmatrix}$.\n",
    "\n",
    "### Part d\n",
    "Observe that by adding the given results, we find that $\\Phi(b_1) = c_1 + 2c_3$; by subtracting, we have $\\Phi(b_2) = -c_1 +c_2 -c_3$. Then $A_\\Phi$ is given by the transpose of the matrix of coefficients, so $A_\\Phi = \\begin{bmatrix}\n",
    "1&-1\\\\\n",
    "0&1\\\\\n",
    "2&-1\n",
    "\\end{bmatrix}$.\n",
    "\n",
    "### Part e\n",
    "We first need to apply $P_1$ to change from basis $B'$ to $B$. Then $A_\\Phi$ will map us to $(\\mathbb{R}^3, C)$, before $P_2$ will take us to $C'$. Remember that matrices are acting like functions here, so they are applied to (column) vectors from right to left. Therefore the multiplication we require is $A'=P_2 A_\\Phi P_1$. (This is what part f is asking us to recognise.)\n",
    "\n",
    "We have $A' = \\begin{bmatrix}\n",
    "0&2\\\\-10&3\\\\\n",
    "12&-4\n",
    "\\end{bmatrix}$.\n",
    "\n",
    "### Part f\n",
    "$P_1 \\begin{bmatrix}2\\\\3\\end{bmatrix}=\\begin{bmatrix}8\\\\9\\end{bmatrix}$.\n",
    "\n",
    "$A_\\Phi \\begin{bmatrix}8\\\\9\\end{bmatrix}=\\begin{bmatrix}-1\\\\9\\\\7\\end{bmatrix}$.\n",
    "\n",
    "$P_2 \\begin{bmatrix}-1\\\\9\\\\7\\end{bmatrix}=\\begin{bmatrix}6\\\\-11\\\\12\\end{bmatrix}$.\n",
    "\n",
    "And observe that $A' \\begin{bmatrix}2\\\\3\\end{bmatrix}=\\begin{bmatrix}6\\\\-11\\\\12\\end{bmatrix}$, indeed!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
